package com.doit.day03

object _05_WordCount {
  def main(args: Array[String]): Unit = {
    val list = List("hello,hello,hi,hi,hadoop",
      "hello,hello,hi,hi,hadoop",
      "hello,hello,hi,hi,hadoop",
      "hello,hello,hi,hi,hadoop")
    //hello 8 ，hi  8   hadoop 4
    //切割
/*    val words: List[String] = list.flatMap(_.split(","))
    //分组
    val map: Map[String, List[String]] = words.groupBy(word=>word)
    //元祖
    val res: Map[String, Int] = map.map(tp => (tp._1, tp._2.size))

    println(res)*/




       list
      .flatMap(_.split(","))
      .groupBy(word=>word)
      .map(tp=>(tp._1,tp._2.size))
      .foreach(println)






    /*val list1: List[Int] = List(1, 2, 3, 4, 5)
    //函数的至简原则
    list1.map((i:Int)=>{i*10})
    //参数只有一个，那么()可以省略
    list1.map(i=>{i*10})
    //如果说，函数体里面只有一行代码，大括号也可以省略
    list1.map(i=>i*10)
    //如果参数在后面的函数体中只用了一次，那么可以用_代替，并且把箭头也省略掉
    list1.map(_*10)

    list1.filter(_%2==0)*/


  }

}
